<?php

namespace app\admin\controller\reward;

use app\common\controller\Backend;
use think\Db;
use app\admin\model\shopro\user\Oauth;
use Exception;
use addons\shopro\exception\Exception as ShoproException;
use think\exception\PDOException;
use app\admin\model\shopro\user\WalletLog;
use think\Model;


/**
 * 红包明细
 *
 * @icon fa fa-user
 */
class Balance extends Backend
{

    protected $relationSearch = true;

    /**
     * @var
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            $searchWhere = $this->request->request('searchWhere');
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $where = "wallet_type = 'money'";
            if( !empty($searchWhere)){
                $where .=" and ( u.id ='".$searchWhere."' or nickname like '%".$searchWhere."%' or mobile like '%".$searchWhere."%')";
            }
            $total = db::name('shopro_user_wallet_log')
                ->alias('w')
                ->join('user u','w.user_id=u.id','left')
                ->whereRaw($where)
                ->count();
            $list = db::name('shopro_user_wallet_log')
                ->alias('w')
                ->field('w.*,u.username,u.nickname,u.mobile')
                ->join('user u','w.user_id=u.id','left')
                ->whereRaw($where)
                ->order('w.id', 'desc')
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list);

            $this->success('用户红包明细', null, $result);
        }
        return $this->view->fetch();
    }
    

}
